function [dy,ds] = LTS(ts, t, y, in_s, in_gates, J_L)
%LTS defines the dynamics of a superficial LTS interneuron

%   y = [V h_L m_L m_ARL]
%   s = [all incoming synapses]
%   V = [all voltages]

global IBIndices;
global LTSIndices;
global LTSCells;
global IB_ACells;

%J_L = 5; %30; (LK) %25; (HK)
g_NaFL = 200;
g_KDRL = 10;
g_ARL = 50; 
g_Leak = 6; g_LL = 5; 
tau_saL_r = 2.5;tau_saL_d = 50; 
tau_sLL_r = 0.5;
tau_sLL_d = 20; C = 1; g_aL = 0.95;
Vk_L = 80;
Vk_a = 0;

dy = zeros(4,1);
ds = zeros(size(in_s));

I_Leak = g_Leak*(65+y(1));
I_NaF = g_NaFL*(m_0i(y(1))^3)*y(2)*(y(1)-50);
I_KDR = g_KDRL*(y(3)^4)*(100+y(1));
I_AR = g_ARL*y(4)*(35+y(1));
%Is_LL = g_LL*y(5)*(y(1)+80)
%Is_aL = g_aL*y(6)*y(1);

Is_all(LTSIndices) = in_gates(LTSIndices).*in_s(LTSIndices)*(y(1)+Vk_L);
Is_all(IBIndices) = in_gates(IBIndices).*in_s(IBIndices)*(y(1)+Vk_a);

dy(1) = (-1/C)*(J_L+I_Leak+I_NaF+I_KDR+I_AR+sum(Is_all));

dy(2) = (1/tau_hi(y(1)))*(h_infi(y(1))-y(2));

dy(3) = (1/tau_mi(y(1)))*(m_infi(y(1))-y(3));

dy(4) = (1/tau_mAR(y(1)))*(m_infAR(y(1),75)-y(4));

%dy(5) = synapse(y(5),tau_sLL_r,tau_sLL_d,V_s(1));

%dy(6) = synapse(y(6),tau_saL_r,tau_saL_d,V_s(2));

for i = 1:length(LTSIndices)
    j = LTSIndices(i);
    ds(j) = synapse(in_s(j), tau_sLL_r, tau_sLL_d, LTSCells(ts, 1, i));
end

for i = 1:length(IBIndices)
    j = IBIndices(i);
    ds(j) = synapse(in_s(j), tau_saL_r, tau_saL_d, IB_ACells(ts, 1, i));
end

end